#import "OperationProgressController.h"


@implementation OperationProgressController

//------------------------------------------------------------------------------
- (void) awakeFromNib
{
	[itemValue setTitleWithMnemonic:@""];
	[operValue setTitleWithMnemonic:@""];
}

//------------------------------------------------------------------------------
- (IBAction)stop:(id)sender
{
	[NSApp stopModal];
}

//------------------------------------------------------------------------------
- (NSWindow*) mainWindow
{
	return mainWindow;
}

//------------------------------------------------------------------------------
- (void) setup:(int)countFiles  operationString:(NSString*)operationString  dest:(NSString*)dest
{
	totalFiles = countFiles;
	filesStarted = 0;

	[progressBar setMinValue: 0];
	[progressBar setMaxValue: countFiles];
	[progressBar setDoubleValue: filesStarted];

	[operLabel setTitleWithMnemonic: [NSString stringWithFormat:@"%@:", operationString]];
	if (nil != dest)
	{
		[mainWindow 
			setTitle: [NSString stringWithFormat:@"%@ images to %@", operationString, [dest lastPathComponent]]];
	}
	else
	{
		[mainWindow setTitle: [NSString stringWithFormat:@"%@ images", operationString]];
	}

	[itemValue setTitleWithMnemonic: @""];
	[operValue setTitleWithMnemonic: [NSString stringWithFormat: @"%u of %u", filesStarted, totalFiles]];
}

//------------------------------------------------------------------------------
- (void) operationComplete
{
	[NSApp abortModal];
}

//------------------------------------------------------------------------------
- (void) startingFile:(NSString*) filename
{
	[itemValue setTitleWithMnemonic: filename];

	++filesStarted;
	[operValue setTitleWithMnemonic: [NSString stringWithFormat: @"%u of %u", filesStarted, totalFiles]];
	[progressBar setDoubleValue: filesStarted];
}

@end
